﻿// <copyright file="ForceAggregator.cs" company="Community Combat Simulator">
//    Community Combat Simulator: a free combat flight simulator.
//    Copyright (C) 2008 Aaron Schinkowitch
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see http://www.gnu.org/licenses/.
// </copyright>
namespace CCSim.Physics
{
    using System;
    using CCSim.Util;
    using CCSim.Vecmath;

    /// <summary>
    /// The force aggregator sums all the forces acting on a rigid body.
    /// </summary>
    internal class ForceAggregator
    {
        /// <summary>
        /// Gravity calculator.
        /// </summary>
        private Gravity gravity;
        
        /// <summary>
        /// Initializes a new instance of the ForceAggregator class.
        /// </summary>
        internal ForceAggregator()
        {
            Gravity = new Gravity();
        }
        
        /// <summary>
        /// Gets or sets the gravity force calculator.
        /// </summary>
        internal Gravity Gravity
        {
            get { return this.gravity; }
            set { this.gravity = value; }
        }
        
        /// <summary>
        /// Sum the forces acting on a rigid body.
        /// </summary>
        /// <param name="rigidBody">The rigid body.</param>
        /// <returns>The sum of all forces acting on the body.</returns>
        internal virtual ForceAndTorque SumForces(RigidBody rigidBody)
        {
            Vector netForce = Gravity.CaluculateForce(rigidBody);
            Vector netTorque = new Vector();
            
            return new ForceAndTorque(netForce, netTorque);
        }

        /// <summary>
        /// Contains a force vector and a torque vector.
        /// </summary>
        internal class ForceAndTorque
        {
            /// <summary>
            /// The force vector.
            /// </summary>
            private Vector force;
            
            /// <summary>
            /// The torque vector.
            /// </summary>
            private Vector torque;
            
            /// <summary>
            /// Initializes a new instance of the ForceAndTorque class with the specified the force
            /// and torque.
            /// </summary>
            /// <param name="force">The force.</param>
            /// <param name="torque">The torque.</param>
            internal ForceAndTorque(Vector force, Vector torque)
            {
                this.force = force;
                this.torque = torque;
            }
            
            /// <summary>
            /// Gets the force.
            /// </summary>
            public Vector Force 
            {
                get { return this.force; }
            }
            
            /// <summary>
            /// Gets the torque.
            /// </summary>
            public Vector Torque
            {
                get { return this.torque; }
            }
        }
    }
}
